package com.slz3.business.module.goodsManagement.gooBrandRecommendGoods.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.goodsManagement.gooBrandRecommendGoods.domain.GooBrandRecommendGoods;
import com.slz3.business.module.goodsManagement.gooBrandRecommendGoods.domain.GooBrandRecommendGoodsFactory;
import com.slz3.business.module.goodsManagement.gooBrandRecommendGoods.steward.GooBrandRecommendGoodsSpecification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

import java.util.List;
import java.util.Optional;
import java.util.UUID;

@Slf4j
@Service
public class GooBrandRecommendGoodsServiceImpl implements GooBrandRecommendGoodsService {
    @Override
    public GooBrandRecommendGoods save(GooBrandRecommendGoods gooBrandRecommendGoods) {
        return Repositorys.gooBrandRecommendGoods.save(GooBrandRecommendGoodsFactory.initBaseFields(gooBrandRecommendGoods));
    }

    @Override
    public Page<GooBrandRecommendGoods> page(MultiValueMap<String, String> params) {
        Page<GooBrandRecommendGoods> gooBrandRecommendGoodsPage = Repositorys.gooBrandRecommendGoods.findAll(
                GooBrandRecommendGoodsSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return gooBrandRecommendGoodsPage;
    }


    @Override
    public GooBrandRecommendGoods modify(GooBrandRecommendGoods gooBrandRecommendGoodsNew) {
        return Repositorys.gooBrandRecommendGoods.saveAndFlush(GooBrandRecommendGoodsFactory.initBaseFields(gooBrandRecommendGoodsNew));
    }

    @Override
    public Optional<GooBrandRecommendGoods> single(UUID uuid) {
        return Repositorys.gooBrandRecommendGoods.findById(uuid);
    }

    @Override
    public List<GooBrandRecommendGoods> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.gooBrandRecommendGoods.findAllById(uuids);
    }

    @Override
    public List<GooBrandRecommendGoods> delete(List<GooBrandRecommendGoods> gooBrandRecommendGoodsList) {
        gooBrandRecommendGoodsList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            GooBrandRecommendGoodsFactory.initBaseFields(item);
        });
        return Services.gooBrandRecommendGoodsTransactional.batchModify(gooBrandRecommendGoodsList);
    }

}
